package org.ywf.agent.consumer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.ywf.agent.JHProperties;
import org.ywf.agent.URLEnum;
import org.ywf.common.entity.RequestData;
import org.ywf.common.okhttp.OkHttpUtils;
import org.ywf.common.request.NewsReq;

/**
 * Http请求层
 */
@Component
public class TwoHttpConsumer extends AbstractAbcConsumer {

    @Autowired
    private JHProperties jhProperties;

    protected String dataCommit(String serviceCode, RequestData<?> requestData) {

        URLEnum urlMap = URLEnum.getUrlMap(serviceCode);
        String url = jhProperties.getUrl()+"/"+urlMap.getHttpUrl();
        NewsReq body = (NewsReq) requestData.getBody();

        String rs = OkHttpUtils.builder().url(url)
                .addParam("key",urlMap.getAuthKey())
                .addParam("type", body.getType())
                .addParam("page",body.getPage())
                .addParam("page_size",body.getPageSize())
                .post(false)
                .sync();

        return rs;
    }
}
